//
//  WebViewController.m
//  SXH
//
//  Created by 房 国生 on 15/6/24.
//  Copyright (c) 2015年 lyss. All rights reserved.
//

#import "WebViewController.h"
#import "YYAnimationIndicator.h"
#import "MBProgressHUD.h"
#import "CommonService.h"

@interface WebViewController () {
    MBProgressHUD *HUD;
    YYAnimationIndicator *indicator;
}

@property (nonatomic, strong) IBOutlet UIWebView *webViewContent;
@property (nonatomic, strong) IBOutlet UILabel *labelTitle;

@end

@implementation WebViewController
@synthesize url, vcTitle, imageShare, contentShare;
@synthesize webViewContent;

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    _labelTitle.text = vcTitle;

    indicator = [[YYAnimationIndicator alloc]initWithFrame:CGRectMake(SCREEN_WIDTH/2-40, SCREEN_HEIGHT/2-40, 80, 57)];
    [indicator setLoadText:Loading_Text];
    [self.view addSubview:indicator];
    
    NSURLRequest *request =[NSURLRequest requestWithURL:[NSURL URLWithString:url]];
    [webViewContent loadRequest:request];
    
    [webViewContent stringByEvaluatingJavaScriptFromString:@"document.body.style.zoom=0.5"];
    [webViewContent setScalesPageToFit:YES];
    [indicator startAnimation];  //开始转动
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/
- (void)webViewDidStartLoad:(UIWebView *)webView
{
    [indicator startAnimation] ;
}

- (void)webViewDidFinishLoad:(UIWebView *)webView
{
    [indicator stopAnimationWithLoadText:HasLoaded_Text withType:YES];
}

- (IBAction)shareAction:(id)sender {
    
    HUD = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    HUD.delegate = self;
    HUD.labelText = Loading_Hard_Text;
    
    NSArray* imageArray = [[NSArray alloc] initWithObjects:imageShare, nil];
    
    [CommonService showShareActionSheet:self.view HUD:HUD
                             ImageArray:imageArray
                                    URL:url
                                  Title:vcTitle
                                Content:contentShare];
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
        if (!contentShare) {
            self.shareBtn.hidden= YES;
        }
    [MobClick beginLogPageView:@"WebViewController"];
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    [MobClick endLogPageView:@"WebViewController"];
}

@end
